//
//  XQLogoutView.swift
//  Spark Peso
//
//  Created by 小琦 on 2025/2/4.
//

import UIKit

class XQLogoutView: UIView {
    
    var sureHandle: (() -> Void)?
    
    var cancelHandle: (() -> Void)?
    
    private lazy var contentView : UIView = {
        let v = UIView()
        return v
    }()
    
    private lazy var bgImageView : UIImageView = {
       let imageView = UIImageView()
        imageView.image = UIImage(named: "logout_bg")
        return imageView
    }()
    
    private lazy var sureBtn : UIButton = {
        let btn = UIButton(type: .custom)
        btn.setTitle("OK", for: .normal)
        btn.setTitleColor(.white, for: .normal)
        btn.backgroundColor = .mainTextColor
        btn.layer.cornerRadius = 24
        btn.addTarget(self, action: #selector(sureClick), for: .touchUpInside)
        return btn
    }()
    
    private lazy var calcelBtn : UIButton = {
        let btn = UIButton(type: .custom)
        btn.setTitle("Close", for: .normal)
        btn.setTitleColor(.white, for: .normal)
        btn.layer.cornerRadius = 24
        btn.layer.borderWidth = 1
        btn.layer.borderColor = UIColor.white.cgColor
        btn.addTarget(self, action: #selector(cancelClick), for: .touchUpInside)
        return btn
    }()
    
    private lazy var titleLb : UILabel = {
       let lb = UILabel()
        lb.text = "Attention"
        lb.textColor = .black
        lb.font = UIFont.boldSystemFont(ofSize: 18)
        return lb
    }()
    
    private lazy var contentLb : UILabel = {
         let lb = UILabel()
         lb.text = "You can get a loan in just one step："
         lb.textColor = .xq_black
         lb.font = UIFont.systemFont(ofSize: 16, weight: .medium)
         return lb
     }()
    
    private lazy var dollorLb : UILabel = {
        let lb = UILabel()
        lb.text = "130,000"
        lb.textColor = .mainTextColor
        lb.font = UIFont.boldSystemFont(ofSize: 50)
        return lb
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.isUserInteractionEnabled = true
        makeUI()
        makeConstraints()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        makeUI()
        makeConstraints()
    }
    
    private func makeUI() {
        self.addSubview(self.contentView)
        self.contentView.addSubview(self.bgImageView)
        self.contentView.addSubview(self.sureBtn)
        self.contentView.addSubview(self.calcelBtn)
        self.bgImageView.addSubview(self.titleLb)
        self.bgImageView.addSubview(self.contentLb)
        self.bgImageView.addSubview(self.dollorLb)
    }
    
    private func makeConstraints() {

        self.contentView.snp.makeConstraints { make in
            make.center.equalToSuperview()
        }
        self.bgImageView.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.width.equalTo(UIDevice.xq_width() - 32)
            make.height.equalTo(255)
        }
        self.sureBtn.snp.makeConstraints { make in
            make.top.equalTo(self.bgImageView.snp.bottom).offset(30)
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.height.equalTo(48)
        }
        self.calcelBtn.snp.makeConstraints { make in
            make.top.equalTo(self.sureBtn.snp.bottom).offset(15)
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.height.equalTo(48)
            make.bottom.equalTo(0)
        }
        self.titleLb.snp.makeConstraints { make in
            make.top.equalTo(37)
            make.centerX.equalToSuperview()
        }
        self.contentLb.snp.makeConstraints { make in
            make.top.equalTo(self.titleLb.snp.bottom).offset(36)
            make.centerX.equalToSuperview()
        }
        self.dollorLb.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(-50)
        }
    }
    
    @objc private func sureClick() {
        sureHandle?()
    }
    
    @objc private func cancelClick() {
        cancelHandle?()
    }
}
